package com.budwk.app.sqfw.services.customservice;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.budwk.app.common.config.AppException;
import com.budwk.app.sqfw.component.CommunityStreetComponent;
import com.budwk.app.sqfw.constants.CommonConstants;
import com.budwk.app.sqfw.models.Sqfw_completeflow;
import com.budwk.app.sqfw.models.Sqfw_formSummary_new;
import com.budwk.app.sqfw.services.SqfwCompleteflowService;
import com.budwk.app.sqfw.services.SqfwFormsummaryNewService;
import com.budwk.app.sqfw.services.common.SqfwCustomForAdminCommonService;
import com.budwk.app.sqfw.vo.CheckDataForAdminVO;
import com.budwk.app.sqfw.vo.GenerateExcelUrlVO;
import com.budwk.app.sqfw.vo.GenerateWordAndPdfUrlVO;
import com.budwk.app.sqfw.vo.SqfwCustomForAdminCommonVO;
import com.budwk.app.sqfwDoc.bo.ExcelCreateConfig;
import com.budwk.app.sqfwV2.dto.dayingRoad.DaYingLuRedRecordPdfDTO;
import com.budwk.app.sqfwV2.dto.dayingRoad.DaYingLuWhiteRecordPdfDTO;
import com.budwk.app.sqfwV2.enums.RedWhite;
import com.budwk.app.sqfwV2.enums.RedWhiteExcel;
import com.budwk.app.sqfwV2.enums.RedWhitePdf;
import com.budwk.app.sqfwV2.generator.dayingRoadPdf.RedHandleCateringRecordsPdfGenerator;
import com.budwk.app.sqfwV2.generator.dayingRoadPdf.WhiteHandleCateringRecordsPdfGenerator;
import com.budwk.app.sqfwV2.service.dayingRoad.DaYingLuRedWhiteRecordExcelService;
import com.budwk.app.sys.models.Sys_user;
import com.budwk.app.sys.services.SysUserService;
import com.budwk.app.util.ClassUtil;
import com.budwk.app.util.adminUtils.CommonCheckUtils;
import com.budwk.app.util.poiUtils.CommonFormOfficeUtils;
import com.budwk.starter.common.page.Pagination;
import com.budwk.starter.common.result.ResultCode;
import com.budwk.starter.security.utils.SecurityUtil;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.xwpf.NiceXWPFDocument;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.nutz.aop.interceptor.ioc.TransAop;
import org.nutz.dao.Cnd;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Criteria;
import org.nutz.dao.util.cri.SqlExpressionGroup;
import org.nutz.dao.util.cri.Static;
import org.nutz.ioc.aop.Aop;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Strings;
import org.apache.commons.lang3.ObjectUtils;

import java.util.*;
import java.util.stream.Collectors;

import static com.budwk.app.util.poiUtils.CommonFormOfficeUtils.createConvergePdfAndUpload;
import static com.budwk.app.util.poiUtils.CommonFormOfficeUtils.generateWordDocument;

/**
 * @program: dfxy-community
 * @description: 大营路街道红白事备案服务实现
 * @author: LJT
 * @create: 2024-02-05 17:11
 **/
@IocBean(name = "DaYingLuRedWhiteRecordForAdminService")
@Slf4j
public class DaYingLuRedWhiteRecordForAdminServiceImpl extends DaYingLuRedWhiteRecordExcelService implements SqfwCustomForAdminCommonService {

    @Inject
    SysUserService sysUserService1;

    @Inject
    private SqfwFormsummaryNewService sqfwFormsummaryNewService;

    @Inject
    private CommunityStreetComponent communityStreetComponent;

    @Inject
    private SqfwCompleteflowService sqfwCompleteflowService;

    private static final String ZHISHU = "直属";// 直属

    @Override
    public Pagination list(SqfwCustomForAdminCommonVO bean) {
        if (StringUtils.isEmpty(bean.getType())) {
            throw new AppException(ResultCode.NOT_FOUND.getMsg());
        }
        long startTime = System.currentTimeMillis();
        // 构造查询条件
        Criteria criteria = buildQueryCond(bean);
        log.info("SqfwCustomForAdminCommonServiceImpl-list-SQL: {}", criteria.toString());
        Pagination pagination = sqfwFormsummaryNewService.listPage(bean.getPageNo(), bean.getPageSize(), criteria);
        List<Sqfw_formSummary_new> sqfwCustomForAdminCommonVOList = pagination.getList(Sqfw_formSummary_new.class);
        if (ObjectUtil.isNotEmpty(sqfwCustomForAdminCommonVOList)) {
            List<SqfwCustomForAdminCommonVO> finalCommonVOList = new ArrayList<SqfwCustomForAdminCommonVO>();
            Map<String, String> pdfUrlMap = CommonCheckUtils.getPdfUrlByFlowId(sqfwCustomForAdminCommonVOList);
            sqfwCustomForAdminCommonVOList.forEach(source -> {
                SqfwCustomForAdminCommonVO target = new SqfwCustomForAdminCommonVO();
                BeanUtil.copyProperties(source, target);
                target.setPdfUrl(pdfUrlMap.get(target.getSqfwFlowId()));
                finalCommonVOList.add(target);
            });
            pagination.setList(finalCommonVOList);
        }
        log.info("SqfwCustomForAdminCommonServiceImpl-list-耗时: {}ms", System.currentTimeMillis() - startTime);
        return pagination;
    }

    @Override
    @Aop(TransAop.READ_COMMITTED)
    public int delete(String id) {
        int num = 0;
        Sqfw_formSummary_new sqfwFormsummaryNew = sqfwFormsummaryNewService.fetch(id);
        if (sqfwFormsummaryNew == null) {
            return num;
        }
        log.info("删除记录:{},{}", SecurityUtil.getUserId(), id);
        sqfwCompleteflowService.deleteAndUpdateWO(sqfwFormsummaryNew.getSqfwFlowId());
        return num;
    }

    @Override
    public int batchDelete(List<String> ids) {
        return 0;
    }

    @Override
    @Aop(TransAop.READ_COMMITTED)
    public int update(Sqfw_formSummary_new sqfwFormsummaryNew) {
        sqfwFormsummaryNew.setUpdateBy(SecurityUtil.getUserId());
        sqfwFormsummaryNew.setUpdateDate(new Date());
        return sqfwFormsummaryNewService.updateIgnoreNull(sqfwFormsummaryNew);
    }

    @Override
    public List<GenerateExcelUrlVO> downloadExcel(List<ExcelCreateConfig> excelConfigList, SqfwCustomForAdminCommonVO bean) {
        if (StringUtils.isEmpty(bean.getType())) {
            throw new AppException(ResultCode.NOT_FOUND.getMsg());
        }
        // 如果formSummaryNewIdList为空，根据条件下载，否则根据勾选id下载
        if (ObjectUtil.isEmpty(bean.getFormSummaryNewIdList()) || bean.getFormSummaryNewIdList().size() <= 0) {
            Criteria criteria = buildQueryCond(bean);
            List<Sqfw_formSummary_new> summaryNewList = sqfwFormsummaryNewService.query(criteria);
            if (summaryNewList.size() > 0) {
                bean.setFormSummaryNewIdList(sqfwFormsummaryNewService.query(criteria).stream().map(Sqfw_formSummary_new::getId).collect(Collectors.toList()));
            } else {
                return new ArrayList<GenerateExcelUrlVO>();
            }
        } else {
            Cnd cnd = Cnd.NEW();
            // 时间
            if (ObjectUtil.isNotEmpty(bean.getQueryStartTime()) && ObjectUtil.isNotEmpty(bean.getQueryEndTime())) {
                cnd.and(Sqfw_formSummary_new::getFillDate, ">=", communityStreetComponent.handleStartQueryTime(bean.getQueryStartTime()));
                cnd.and(Sqfw_formSummary_new::getFillDate, "<=", communityStreetComponent.handleEndQueryTime(bean.getQueryEndTime()));
            }
            cnd.and(Sqfw_formSummary_new::getId, "IN", bean.getFormSummaryNewIdList());
            List<Sqfw_formSummary_new> summaryNewList = sqfwFormsummaryNewService.query(cnd);
            if (summaryNewList.size() > 0) {
                bean.setFormSummaryNewIdList(summaryNewList.stream().map(Sqfw_formSummary_new::getId).collect(Collectors.toList()));
            } else {
                return new ArrayList<GenerateExcelUrlVO>();
            }
        }
        return super.generateExcelForAdmin(excelConfigList, SecurityUtil.getUserId(), bean.getFormSummaryNewIdList());
    }

    @Override
    public GenerateWordAndPdfUrlVO downloadPdf(List<ExcelCreateConfig> excelConfigList, SqfwCustomForAdminCommonVO bean) {
        return null;
    }

    @Override
    public List<GenerateExcelUrlVO> downloadPdfList(List<ExcelCreateConfig> excelConfigList, SqfwCustomForAdminCommonVO bean) {
        if (StringUtils.isEmpty(bean.getType())) {
            throw new AppException(ResultCode.NOT_FOUND.getMsg());
        }
        // 如果formSummaryNewIdList为空，根据条件下载，否则根据勾选id下载
        if (ObjectUtil.isEmpty(bean.getFormSummaryNewIdList()) || bean.getFormSummaryNewIdList().size() <= 0) {
            Criteria criteria = buildQueryCond(bean);
            List<Sqfw_formSummary_new> summaryNewList = sqfwFormsummaryNewService.query(criteria);
            if (summaryNewList.size() > 0) {
                bean.setFormSummaryNewIdList(summaryNewList.stream().map(Sqfw_formSummary_new::getId).collect(Collectors.toList()));
            } else {
                return new ArrayList<GenerateExcelUrlVO>();
            }
        } else {
            Cnd cnd = Cnd.NEW();
            cnd.and(Sqfw_formSummary_new::getId, "IN", bean.getFormSummaryNewIdList());
            List<Sqfw_formSummary_new> summaryNewList = sqfwFormsummaryNewService.query(cnd);
            if (summaryNewList.size() > 0) {
                bean.setFormSummaryNewIdList(summaryNewList.stream().map(Sqfw_formSummary_new::getId).collect(Collectors.toList()));
            } else {
                return new ArrayList<GenerateExcelUrlVO>();
            }
        }
        return downPdfList(excelConfigList, bean.getFormSummaryNewIdList(), "", "");
    }

    // 生成pdf方法
    public List<GenerateExcelUrlVO> downPdfList(List<ExcelCreateConfig> excelConfigList, List<String> ids,
                                                String startTime, String endTime) {
        if (ObjectUtil.isEmpty(ids)) {
            throw new AppException(ResultCode.NULL_DATA_ERROR.getMsg());
        }
        StringBuffer sb = new StringBuffer();
        for (String id : ids) {
            sb.append("'").append(id).append("',");
        }
        List<GenerateExcelUrlVO> generateExcelUrlVOS = new ArrayList<>();
        for (ExcelCreateConfig config : excelConfigList) {
            // 模板下载
            if (config.getOnlyGenerateTemplateFlag()) {
                GenerateExcelUrlVO urlVO = new GenerateExcelUrlVO();
                String url = downWordTemplate(config);
                urlVO.setExcelUrl(url);
                generateExcelUrlVOS.add(urlVO);
                return generateExcelUrlVOS;
            }
            // 数据下载
            String fileName;
            String celebratoryEvents;
            if (RedWhitePdf.RED_TRACKING_REPORT.getCode().equals(config.getFileIdentity())) {
                fileName = RedWhitePdf.RED_TRACKING_REPORT.getName();
                celebratoryEvents = RedWhite.RED.getName();
            } else {
                fileName = RedWhitePdf.WHITE_INFORMATION_STATISTICS.getName();
                celebratoryEvents = RedWhite.WHITE.getName();
            }
            String sql = "select sc.resource_path from shequ.sqfw_completeflow sc left join shequ.sqfw_form_summary_new sfsn " +
                    "on sc.id = sfsn.sqfw_flow_id where " +
                    "sfsn.param_data->>'celebratoryEvents' = '" + celebratoryEvents + "' and sfsn.id IN (" + sb.substring(0, sb.length() - 1) + ") " +
                    "and sc.resource_path != 'error' and sc.resource_path != 'creating' ";
            if (org.apache.commons.lang3.StringUtils.isNotBlank(startTime)) {
                sql += "and sfsn.fill_date >= '" + startTime + "' ";
            }
            if (org.apache.commons.lang3.StringUtils.isNotBlank(endTime)) {
                sql += "and sfsn.fill_date <= '" + endTime + " 23:59:59' ";
            }
            sql += "order by sc.create_date asc";
            List<Sqfw_completeflow> completeFlowList = sqfwCompleteflowService.listEntity(Sqls.create(sql));

            GenerateExcelUrlVO generateExcelUrlVO = new GenerateExcelUrlVO();
            generateExcelUrlVO.setFileIdentity(config.getFileIdentity());

            if (completeFlowList != null && completeFlowList.size() > 0) {
                generateExcelUrlVO.setCreateConditionFlag(true);
            } else {
                generateExcelUrlVO.setCreateConditionFlag(false);
            }

            // 数据检测
            if (!config.getCreateExcelFileFlag() || completeFlowList == null || completeFlowList.size() == 0) {
                generateExcelUrlVOS.add(generateExcelUrlVO);
                continue;
            }

            List<String> pdfList = completeFlowList.stream().map(Sqfw_completeflow::getResourcePath).collect(Collectors.toList());

            try {
                String url = createConvergePdfAndUpload(pdfList, fileName);
                generateExcelUrlVO.setExcelUrl(url);
            } catch (Exception e) {
                e.printStackTrace();
            }
            generateExcelUrlVOS.add(generateExcelUrlVO);
        }
        return generateExcelUrlVOS;
    }

    @Override
    public Criteria buildQueryCond(SqfwCustomForAdminCommonVO bean) {
        Criteria cri = Cnd.cri();
        SqlExpressionGroup criSql = cri.where();

        if (StringUtils.isEmpty(bean.getType())) {
            throw new AppException(ResultCode.NOT_FOUND.getMsg());
        }
        // 组装查询条件
        if (StringUtils.isNotBlank(bean.getPageOrderName()) && Strings.isNotBlank(bean.getPageOrderBy())) {
            if (bean.getPageOrderBy().equals(CommonConstants.ASC)) {
                cri.getOrderBy().asc(bean.getPageOrderName());
            }
            if (bean.getPageOrderBy().equals(CommonConstants.DESC)) {
                cri.getOrderBy().desc(bean.getPageOrderName());
            }
        } else {
            cri.getOrderBy().desc(Sqfw_formSummary_new::getFillDate);
        }
        // 类型
        criSql.andEquals(SqfwCustomForAdminCommonVO::getType, bean.getType());

        Sys_user sysUser = sysUserService1.fetch(SecurityUtil.getUserId());
        if (ObjectUtils.isEmpty(sysUser)) {
            throw new AppException(ResultCode.USER_NOT_FOUND.getMsg());
        }
        // 区域5级检查
        CommonCheckUtils.checkAreaRange(criSql);
        // 省
        if (StringUtils.isNotBlank(bean.getProvince()) && !CommonCheckUtils.ZHISHU.equals(bean.getProvince())) {
            criSql.andEquals(SqfwCustomForAdminCommonVO::getProvince, bean.getProvince());
        }
        // 市
        if (StringUtils.isNotBlank(bean.getCity()) && !CommonCheckUtils.ZHISHU.equals(bean.getCity())) {
            criSql.andEquals(SqfwCustomForAdminCommonVO::getCity, bean.getCity());
        }
        // 区
        if (StringUtils.isNotBlank(bean.getDistrict()) && !CommonCheckUtils.ZHISHU.equals(bean.getDistrict())) {
            criSql.andEquals(SqfwCustomForAdminCommonVO::getDistrict, bean.getDistrict());
        }
        // 街道
        if (StringUtils.isNotBlank(bean.getCounty()) && !CommonCheckUtils.ZHISHU.equals(bean.getCounty())) {
            criSql.andEquals(SqfwCustomForAdminCommonVO::getCounty, bean.getCounty());
        }
        // 时间
        if (ObjectUtil.isNotEmpty(bean.getQueryStartTime()) && ObjectUtil.isNotEmpty(bean.getQueryEndTime())) {
            criSql.andBetween(Sqfw_formSummary_new::getFillDate,
                    communityStreetComponent.handleStartQueryTime(bean.getQueryStartTime()),
                    communityStreetComponent.handleEndQueryTime(bean.getQueryEndTime()));
        }
        // 辖区
        if (StringUtils.isNotBlank(bean.getCommunity()) && !CommonCheckUtils.ZHISHU.equals(bean.getCommunity())) {
            criSql.andEquals(Sqfw_formSummary_new::getCommunity, bean.getCommunity());
        }
        // 全局搜索
        if (StringUtils.isNotEmpty(bean.getQueryAll())) {
            SqlExpressionGroup celebratoryEvents = Cnd.exps(new Static("param_data->>'celebratoryEvents' like '%" + bean.getQueryAll() + "%'"));
            SqlExpressionGroup nameRecordKeeper = Cnd.exps(new Static("param_data->>'nameRecordKeeper' like '%" + bean.getQueryAll() + "%'"));
            SqlExpressionGroup community = Cnd.exps(new Static("community like '%" + bean.getQueryAll() + "%'"));
            SqlExpressionGroup createUserName = Cnd.exps(new Static("create_user_name like '%" + bean.getQueryAll() + "%'"));
            criSql.and(celebratoryEvents.or(nameRecordKeeper).or(community).or(createUserName));
        }
        // 需要排除的数据
        criSql.andNotEquals(Sqfw_formSummary_new::getFillDate, CommonConstants.WASTE_CREATE_TIME);
        // 备案类型
        if (StringUtils.isNotBlank(bean.getCelebratoryEvents())) {
            criSql.andEquals("param_data->>'celebratoryEvents'", bean.getCelebratoryEvents());
        }
        // 备案人姓名
        if (StringUtils.isNotBlank(bean.getNameRecordKeeper())) {
            criSql.andEquals("param_data->>'nameRecordKeeper'", bean.getNameRecordKeeper());
        }
        // 备案人是否党员
        if (ObjectUtil.isNotEmpty(bean.getIsPartyMemberRecordKeeper())) {
            criSql.andEquals("param_data->>'isPartyMemberRecordKeeper'", bean.getIsPartyMemberRecordKeeper().toString());
        }
        // 酒席形式
        if (StringUtils.isNotBlank(bean.getBanquetForm())) {
            criSql.andEquals("param_data->>'banquetForm'", bean.getBanquetForm());
        }
        return cri;
    }

    @Override
    public List<CheckDataForAdminVO> checkDataInfoList(SqfwCustomForAdminCommonVO bean) {
        if (StringUtils.isEmpty(bean.getType())) {
            throw new AppException(ResultCode.NOT_FOUND.getMsg());
        }
        List<Sqfw_formSummary_new> summaryNewList = new ArrayList<Sqfw_formSummary_new>();
        // 如果formSummaryNewIdList为空，根据条件下载，否则根据勾选id下载
        if (ObjectUtil.isEmpty(bean.getFormSummaryNewIdList()) || bean.getFormSummaryNewIdList().size() <= 0) {
            Criteria criteria = buildQueryCond(bean);
            summaryNewList = sqfwFormsummaryNewService.query(criteria);
        } else {
            Cnd cnd = Cnd.NEW();
            cnd.and(Sqfw_formSummary_new::getId, "IN", bean.getFormSummaryNewIdList());
            summaryNewList = sqfwFormsummaryNewService.query(cnd);
        }
        List<CheckDataForAdminVO> checkDataForAdminVOList = new ArrayList<CheckDataForAdminVO>();
        // excel
        for (RedWhiteExcel item : RedWhiteExcel.values()) {
            CheckDataForAdminVO checkDataForAdminVO = new CheckDataForAdminVO();
            checkDataForAdminVO.setFileIdentity(item.getCode());
            checkDataForAdminVO.setFileName(RedWhiteExcel.getName(item.getCode()) + ".xlsx");
            checkDataForAdminVO.setCreateConditionFlag(false);
            checkDataForAdminVOList.add(checkDataForAdminVO);
        }
        if (summaryNewList.size() <= 0) {
            return checkDataForAdminVOList;
        }
        // 判断是否可下载
        List<Sqfw_formSummary_new> finalSummaryNewList = summaryNewList;
        checkDataForAdminVOList.forEach(item -> {
            if (item.getFileIdentity().equals(RedWhiteExcel.WHITE_SELF_CATERING_STATISTICS.getCode())) {
                for (Sqfw_formSummary_new sqfwFormSummaryNew : finalSummaryNewList) {
                    JSONObject jsonObject = JSON.parseObject(sqfwFormSummaryNew.getParamData());
                    String key = ClassUtil.getField(DaYingLuWhiteRecordPdfDTO::getCelebratoryEvents);
                    // 当{{是否本辖区居民}}=是，{{是否在殡仪馆治丧}}=否，数据才进入该模板
                    String isLocalResidentKey = ClassUtil.getField(DaYingLuWhiteRecordPdfDTO::getIsLocalResident);
                    String isInFuneralHomeKey = ClassUtil.getField(DaYingLuWhiteRecordPdfDTO::getIsInFuneralHome);
                    if (RedWhite.WHITE.getName().equals(jsonObject.get(key))
                            && jsonObject.getBoolean(isLocalResidentKey) && !jsonObject.getBoolean(isInFuneralHomeKey)) {
                        item.setCreateConditionFlag(true);
                        break;
                    }
                }
            } else if (item.getFileIdentity().equals(RedWhiteExcel.WHITE_WORK_PROMOTION.getCode())) {
                item.setCreateConditionFlag(true);
            } else if (item.getFileIdentity().equals(RedWhiteExcel.WHITE_INFORMATION_STATISTICS.getCode())) {
                item.setCreateConditionFlag(true);
            } else if (item.getFileIdentity().equals(RedWhiteExcel.RED_TRACKING_REPORT.getCode())) {
                for (Sqfw_formSummary_new sqfwFormSummaryNew : finalSummaryNewList) {
                    JSONObject jsonObject = JSON.parseObject(sqfwFormSummaryNew.getParamData());
                    String key = ClassUtil.getField(DaYingLuRedRecordPdfDTO::getCelebratoryEvents);
                    if (RedWhite.RED.getName().equals(jsonObject.get(key))) {
                        item.setCreateConditionFlag(true);
                        break;
                    }
                }
            } else if (item.getFileIdentity().equals(RedWhiteExcel.WHITE_TRACKING_REPORT.getCode())) {
                for (Sqfw_formSummary_new sqfwFormSummaryNew : finalSummaryNewList) {
                    JSONObject jsonObject = JSON.parseObject(sqfwFormSummaryNew.getParamData());
                    String key = ClassUtil.getField(DaYingLuRedRecordPdfDTO::getCelebratoryEvents);
                    if (RedWhite.WHITE.getName().equals(jsonObject.get(key))) {
                        item.setCreateConditionFlag(true);
                        break;
                    }
                }
            }
        });
        return checkDataForAdminVOList;
    }

    @Override
    public void reGeneratePdf(String id) {

    }

    /**
     * 下载模板
     *
     * @param config
     * @return
     */
    private String downWordTemplate(ExcelCreateConfig config) {
        String fileName = "";
        String templateName = "";

        Map<String, Object> dataMap = JSONUtil.parseObj(new Sqfw_formSummary_new(), false);
        if (RedWhitePdf.WHITE_INFORMATION_STATISTICS.getCode().equals(config.getFileIdentity())) {
            fileName = RedWhitePdf.WHITE_INFORMATION_STATISTICS.getName();
            templateName = new WhiteHandleCateringRecordsPdfGenerator().getTemplateName();
            dataMap.putAll(JSONUtil.parseObj(new DaYingLuWhiteRecordPdfDTO(), false));
        }
        if (RedWhitePdf.RED_TRACKING_REPORT.getCode().equals(config.getFileIdentity())) {
            fileName = RedWhitePdf.RED_TRACKING_REPORT.getName();
            templateName = new RedHandleCateringRecordsPdfGenerator().getTemplateName();
            dataMap.putAll(JSONUtil.parseObj(new DaYingLuRedRecordPdfDTO(), false));
        }

        for (String key : dataMap.keySet()) {
            dataMap.put(key, "");
        }

        dataMap.put("yyyy", "");
        dataMap.put("mm", "");
        dataMap.put("dd", "");
        dataMap.put("hh", "");
        dataMap.put("checkedUnitLeaders", new ArrayList<>());
        dataMap.put("fillDateStr", "");

        XWPFTemplate xwpfTemplate = generateWordDocument(dataMap, null, templateName);
        NiceXWPFDocument xwpfDocument = xwpfTemplate.getXWPFDocument();
        GenerateWordAndPdfUrlVO vo = CommonFormOfficeUtils.wordUpload(Arrays.asList(xwpfDocument), fileName.replace("合集", "模板"));
        return vo.getWordUrl();
    }
}
